package com.hbnu.net;

import java.io.*;
import java.net.Socket;

public class TcpClientDemo3 {
    public static void main(String[] args) {
        try {
            Socket socket = new Socket("127.0.0.1",9999);

            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));       //获取键盘输入

            BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));      //向服务端发送数据

            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));     //获取服务端返回的数据

            String line = null;
            while ((line = bufferedReader.readLine()) != null) {
                if ("bye".equalsIgnoreCase(line)) {
                    break;
                }
                out.write(line);        //向服务端发送数据

                String result = in.readLine();
                System.out.println("服务端返回的结果" + result);

            }

            bufferedReader.close();
            socket.close();

        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
